package com.toweave.starter.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.toweave.starter.R;

public class AnimatorTestActivity extends AppCompatActivity implements View.OnClickListener {

  private TextView btn_animator_starter;
  private View btn_animator_test;
  private Button btn_animator_xml;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animator_test);

    btn_animator_starter = findViewById(R.id.btn_animator_starter);
    btn_animator_starter.setOnClickListener(this);

    btn_animator_test = findViewById(R.id.btn_animator_test);
    btn_animator_test.setOnClickListener(this);

    btn_animator_xml = findViewById(R.id.btn_animator_xml);
    btn_animator_xml.setOnClickListener(this);
  }

  @Override
  public void onClick(View v) {

    int id = v.getId();
    if (id == R.id.btn_animator_starter) {
      AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this,
          R.animator.property_animator);
      set.setTarget(btn_animator_starter);
      set.start();
    } else if (id == R.id.btn_animator_test) {
      PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
      PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
      ObjectAnimator.ofPropertyValuesHolder(btn_animator_test, pvhX, pvhY).start();
    } else if (id == R.id.btn_animator_xml) {
      AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this,
          R.animator.property_animator);
      set.setTarget(btn_animator_xml);
      set.start();
    }
    return;
  }
}